﻿@inject ContentService _contentService
@{
    var categoryId = ViewContext.RouteData.Values["categoryId"].To<int>(0);
    var categories = await _contentService.GetCategoriesByParentAsync(0);
    var pageName = ViewContext.RouteData.Values["page"].ToString().ToLower();
    Channels? currentChannel = null;
    if (ViewContext.HttpContext.Request.Query["channel"].Any())
    {
        currentChannel = (Enum.Parse<Channels>(ViewContext.HttpContext.Request.Query["channel"].ToString(), true));
    }

    //分类显示的页面数组
    var includePageNames = new[] { "/content/index","/index"};

    bool showCategory = false;

    foreach (var item in includePageNames)
    {
        if (pageName.ToLower()==item)
        {
            showCategory = true;
            continue;
        }
    }

}

@if (showCategory)
{

<div class="row mt-3 mb-3">
    <div class="col">
        @if (currentChannel.HasValue)
        {
        <h1>
            @currentChannel.Value.GetDescription()
        </h1>
        }
    </div>
    <div class="col-10">
        <ul class="list-inline">

            <li class="list-inline-item @if (categoryId==0) { <text>bg-primary p-3 text-white</text>} ">
                <a asp-page="/Content/Index" asp-route-categoryId="@null" asp-route-channel="@currentChannel" class="@if (categoryId==0) { <text>text-white</text>}">
                    全部分类
                </a>
            </li>
            @foreach (var item in categories)
            {

                <li class="list-inline-item @if (item.Id == categoryId) { <text>bg-primary p-3 text-white</text>} ">
                    <a asp-page="/Content/Index" asp-route-categoryId="@item.Id" asp-route-channel="@currentChannel" class="@if (item.Id == categoryId) { <text>text-white</text>}">
                        @item.Name
                    </a>
                </li>
            }
        </ul>
    </div>
</div>

}